package it.eporicerca.enea.ejb.interceptors;

import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;

public class PerfomanceProfiler {

	@AroundInvoke
	public Object intercept(InvocationContext ctx) throws Exception
	{
		System.out.println("hello PerfomanceProfiler");
		long start = System.currentTimeMillis();
		long end = 0;
		try{
			Object obj = ctx.proceed();
			end =  System.currentTimeMillis();
			return obj;
		}catch (Exception e) {
			throw e;
		}
		finally
		{
			System.out.println("Invocation time of method "+ctx.getMethod().getName()+" of bean"+ctx.getTarget().getClass()+" : "+(end-start)+" ms");
		}


	}
}
